package com.spc.car.web.controller.adm;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spc.car.core.framework.web.domain.AjaxResult;
import com.spc.car.data.domain.adm.po.AdmPrivateVehiclePO;
import com.spc.car.data.domain.adm.vo.AdmVehlicePrivateVO;
import com.spc.car.data.entity.adm.AdmPrivateVehicleInfo;
import com.spc.car.data.service.adm.AdmPrivateVehicleInfoService;
import com.spc.car.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "车辆信息(私车车辆管理)")
@Slf4j
@Validated
@RestController
@RequestMapping("/admPrivateVehicle")
public class PrivateVehicleController extends BaseController {

    @Autowired
    AdmPrivateVehicleInfoService privateVehicleInfoService;

    @ApiOperation(value = "保存私车车辆信息", notes = "保存私车车辆信息（私车）")
    @PostMapping("/savePrivateVehicle")
    public AjaxResult savePrivateVehicle(@Valid @RequestBody AdmVehlicePrivateVO vehlicePrivateVO) {
        boolean result = privateVehicleInfoService.addOrUpdate(vehlicePrivateVO);
        return result ? AjaxResult.success("保存成功！") : AjaxResult.error("保存失败！");
    }

    @ApiOperation(value = "获取私车车辆信息", notes = "获取车辆信息")
    @GetMapping("/getPrivateVehicle")
    @ApiImplicitParam(value = "ID", name = "id", required = true, type = "Long")
    public AjaxResult getPrivateVehicle(Long id) {
        AdmPrivateVehicleInfo admPrivateVehicleInfo = privateVehicleInfoService.getById(id);
        return AjaxResult.success("获取成功！", admPrivateVehicleInfo);
    }

    @ApiOperation(value = "私车车辆信息列表", notes = "车辆信息列表")
    @PostMapping("/listPrivateVehicle")
    public AjaxResult listPrivateVehicle(@RequestBody AdmPrivateVehiclePO admPrivateVehiclePO) {
        IPage page = privateVehicleInfoService.page(admPrivateVehiclePO.getPage(), admPrivateVehiclePO.toWrapper());
        return AjaxResult.success("查询成功！", page);
    }

    @ApiOperation(value = "删除私车车辆信息", notes = "删除私车车辆信息")
    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestParam(name = "id", required = true) Long id) {
        privateVehicleInfoService.removeById(id);
        return AjaxResult.success("删除成功！");
    }
}
